package org.functional.demo;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * @author Zhang Yu
 * @description: TODO
 * @date 2024/5/14 15:07
 */
public class StreamDemo2 {

    public static void main(String[] args) {
//        test1();
//        test2();
        test3();

    }


    static void test3(){
        List<Integer> arrays = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
        arrays.stream().map(Integer::valueOf).limit(5).forEach(System.out::println);
    }

    static void test2() {
        Stream<BigInteger> naturals = createNaturalStream();
        naturals.map(n -> n.multiply(n))
                .limit(100)
                .forEach(System.out::println);
    }

    static void test1() {
        Stream<BigInteger> naturals = createNaturalStream();
        Stream<BigInteger> s2 = naturals.map(n->n.multiply(n));
        Stream<BigInteger> s3 = s2.limit(100);
        s3.forEach(System.out::println);
    }


    public static Stream<BigInteger> createNaturalStream() {
        return Stream.generate(new Supplier<BigInteger>() {
            BigInteger bigInteger = BigInteger.valueOf(0);
            @Override
            public BigInteger get () {
                bigInteger = bigInteger.add(BigInteger.valueOf(1));
                return bigInteger;
            }
        });
    }

}
